// Global.cpp: implementation of the Global class.
//
//////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "Global.h"
#include "AcGeExt.h"
#include <math.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

namespace Global
{
	INT CountOfSubStrings ( CONST CString& strOwner, LPCTSTR szSub )
	{
		INT iCurPos = 0;
		INT iPrePos = 0;
		INT iRet = 0;
		while ( ( iCurPos = strOwner.Find( szSub, iPrePos ) ) != -1 )
		{
			iPrePos = iCurPos + 1;
			iRet++;
		}
		return iRet;
	}

	INT CountOfSubStrings ( CONST CString& strOwner, TCHAR ch )
	{
		INT iCurPos = 0;
		INT iPrePos = 0;
		INT iRet = 0;
		while ( ( iCurPos = strOwner.Find( ch, iPrePos ) ) != -1 )
		{
			iPrePos = iCurPos + 1;
			iRet++;
		}
		return iRet;
	}

	bool GetFilePathAndTitle( const CString& fullPath, CString& path, CString& title )
	{
		int index = fullPath.ReverseFind( _T( '\\' ) );
		assert( index > 0 && index < fullPath.GetLength() - 1 );
		title = fullPath.Mid( index + 1 );
		path = fullPath.Left( index );
		return true;
	}
	
	void SetURL( CString& url, const CString& inputurl ) throw ( TextException )
	{
		url = inputurl;
		url.TrimRight();
		if ( url.GetLength() == 0 ) throw TextException();
		if ( url.GetAt( url.GetLength() - 1 ) != _T( '\\' ) )
			url += _T( '\\' );
	}

}

